<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <link rel="stylesheet" th:href="@{/adminlte/layui/css/layui.css}"  media="all"/>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<div class="demoTableOverGoodsInstock">
    <div class="layui-inline" style="margin-left:0px">生产单号：</div>
    <div class="layui-inline" style="width: 220px">
        <input class="layui-input"  id="productNumSearchOverGoodsInstock" autocomplete="off" style="width: 200px;height: 25px" placeholder="请输入生产单号"/>
    </div>
    产品名称：
    <div class="layui-inline" style="width: 220px;">
       <!-- <input class="layui-input"  id="goodsNameSearch" autocomplete="off" style="width: 200px;height: 25px"  placeholder="请输入产品名称"/>-->
        <select id="goodsNameSearchOverGoodsInstock" name="goodsNameSearchOverGoodsInstock" lay-verify=""  style="width: 200px">
            <option value="" >请选择产品名称</option>
            <option th:each="goodsNameP1:${goodsNameP}" th:value="${goodsNameP1.dataname}" th:text="${goodsNameP1.dataname}"></option>
        </select>
    </div>
    产品规格：
    <div class="layui-inline" style="width: 220px">
       <!-- <input class="layui-input"  id="goodsSpecificationsSearch" autocomplete="off" style="width: 200px;height: 25px" placeholder="请输入产品规格"/>-->
        <select id="goodsSpecificationsSearchOverGoodsInstock"  style="width: 200px">
            <option  value="">请选择产品规格</option>
            <option th:each="specificationsP1:${specificationsP}" th:value="${specificationsP1.dataname}" th:text="${specificationsP1.dataname}"></option>
        </select>
    </div>
    <div class="layui-inline" style="margin-left: -15px">操作员名称：</div>
    <div class="layui-inline" style="width: 220px">
        <input class="layui-input"  id="operatorSearchOverGoodsInstock" autocomplete="off" style="width: 200px;height: 25px" placeholder="请输入操作员名称"/>
    </div><br/>
    起始日期：
    <div class="layui-inline" style="width: 220px">
        <input class="layui-input"  id="startDateSearchOverGoodsInstock" autocomplete="off" style="width: 200px;height: 25px" placeholder="请选择起始日期"/>
    </div>
    截止日期：
    <div class="layui-inline" style="width: 220px">
        <input class="layui-input"  id="endDateSearchOverGoodsInstock" autocomplete="off" style="width: 200px;height: 25px" placeholder="请选择截止日期"/>
    </div>
    <button class="layui-btn layui-btn-sm" data-type="reload">查询</button>
</div>
<div id="add-mainOverIn" style="display: none;">
    <div class="my-form">
        <div class="layui-form-item my-form-item" style="margin-top: 20px;margin-left: -40px">
            <label class="layui-form-label layui-icon"  style="width: 170px;">生产单号:</label>
            <div class="layui-input-inline">
                <input id="productNumAdd123" type="text" name="productNumAdd123" autocomplete="off" placeholder="请输入生产单号"
                       class="layui-input" onblur="searchExist()"/>
                <p id="productNumAddS" style="color: red; display: none" >生产单号已被使用</p>
                <p id="productNumAddSS" style="color: red; display: none" >未找到该生产单号</p>
            </div>
        </div>
        <div class="layui-form-item my-form-item"  style="margin-left: -40px">
            <label class="layui-form-label layui-icon"  style="width: 170px">数量:</label>
            <div class="layui-input-inline">
                <input id="nums123" type="text" name="nums123"  autocomplete="off" placeholder="请输入数量"
                       class="layui-input" onkeyup="value=value.replace(/[^\d]/g,'')"/>
            </div>
        </div>
        <div class="layui-form-item my-form-item"  style="margin-left: -40px">
            <label class="layui-form-label layui-icon"  style="width: 170px">备注:</label>
            <div class="layui-input-inline">
                <input id="remarksAdd123" type="text" name="remarksAdd123"  autocomplete="off" placeholder="请输入备注"
                       class="layui-input"/>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="toolbarDemoOverGoodsIn">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="adds"  >添加</button>
        <!--<button class="layui-btn layui-btn-sm" lay-event="update" id="update" >修改</button>-->
        <button class="layui-btn layui-btn-sm" lay-event="deletes"  >删除</button>
       <!-- <button class="layui-btn layui-btn-sm" lay-event="upload" id="upload" >导入</button>-->
    </div>
</script>
<table class="layui-table" lay-data="{totalRow:true,url:'/overGoods/queryOverGoodsInStock', page:true, id:'idTestOverIn',toolbar:'#toolbarDemoOverGoodsIn',defaultToolbar:['filter', 'print','exports'] }" lay-filter="demoOverIn">
    <thead>
    <tr>
        <th lay-data="{type:'checkbox', fixed: 'left'}" rowspan="2"></th>
        <th lay-data="{align:'center'}" colspan="5">订单信息</th>
        <th lay-data="{align:'center'}" colspan="4">阀门信息</th>
        <th lay-data="{align:'center'}" colspan="4">控制主板信息</th>
        <th lay-data="{align:'center'}" colspan="4">通讯主板信息</th>
        <th lay-data="{align:'center'}" colspan="4">485主板信息</th>
        <th lay-data="{field:'testDate', width:180}" rowspan="2">生产日期</th>   <!-- totalRowText:'合计：'-->
        <!--<th lay-data="{field:'goodsStock', width:150 }">入库仓库</th>-->
        <!--<th lay-data="{field:'addGoodsNums', width:150,totalRow:true}">入库后数量</th>-->
        <th lay-data="{field:'operator', width:150}" rowspan="2">操作人</th>
        <th lay-data="{field:'operatorTime', width:180}" rowspan="2">操作时间</th>
        <th lay-data="{field:'testRemarks', width:500}" rowspan="2">备注</th>
    </tr>
    <tr>
        <th lay-data="{field:'productNum', width:150}">生产单号</th>
        <th lay-data="{field:'goodsName', width:150}">产品名称</th>
        <th lay-data="{field:'specifications', width:150}">产品规格</th>
        <th lay-data="{field:'pressure', width:150,totalRowText:'合计：'}" >使用压力</th>
        <th lay-data="{field:'nums', width:150,totalRow:true,totalRow:true}">入库数量</th>
        <th lay-data="{field:'valveSupplier', width:150}">阀门厂商</th>
        <th lay-data="{field:'valveName', width:150}">阀门名称</th>
        <th lay-data="{field:'valveSpecifications', width:150}">阀门规格</th>
        <th lay-data="{field:'intakeDirection', width:150}">进气方向</th>
        <th lay-data="{field:'controlMainboardSupplier', width:150}">控制主板厂商</th>
        <th lay-data="{field:'controlMainboardName', width:150}">控制主板名称</th>
        <th lay-data="{field:'controlMainboardSpecifications', width:150}">型号规格</th>
        <th lay-data="{field:'version', width:150}">程序版本</th>
        <th lay-data="{field:'telMainBoardSupplier', width:150}">通讯主板厂商</th>
        <th lay-data="{field:'telMainBoardName', width:150}">通讯主板名称</th>
        <th lay-data="{field:'telMainBoardSpecifications', width:150}">型号规格</th>
        <th lay-data="{field:'telType', width:150}">通讯方式</th>
        <th lay-data="{field:'fourSupplier', width:150}">485主板厂商</th>
        <th lay-data="{field:'fourMainBoardName', width:150}">485主板名称</th>
        <th lay-data="{field:'fourSpecifications', width:150}">型号规格</th>
        <th lay-data="{field:'telProtocol', width:150}">通信协议</th>

    </tr>
    </thead>
</table>

<script th:src="@{/adminlte/layui/layui.all.js}" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use('table', function(){
        var table = layui.table;
        //监听表格复选框选择
        table.on('checkbox(demoOverIn)', function(obj){
            console.log(obj)
        });
        //监听工具条
        table.on('tool(demoOverIn)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                layer.msg('ID：'+ data.id + ' 的查看操作');
            } else if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                /*layer.alert('编辑行：<br/>'+ JSON.stringify(data))*/

            }
        });
        //监听头工具栏事件
        table.on('toolbar(demoOverIn)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id)
                ,data = checkStatus.data//获取选中的数据
                ,deList=[1];
            data.forEach(function (n,i) {
                deList.push(n.id)
            });
            deList.push(2);
            switch(obj.event){
                case 'adds':
                    layer.open({
                        type:1,
                        title:'添加',
                        btnAlign: 'c',
                        area: ['370px', '300px'],
                        content: $("#add-mainOverIn"),
                        btn:['保存','取消'],
                        success:function(){
                           top.$('#productNumAdd123').val("");
                           top.$("#remarksAdd123").val("");
                           top.$("#nums123").val("");
                        },
                        yes:function(index,layero){
                            var productNum =top.$('#productNumAdd123').val();
                            var testRemarks =top.$("#remarksAdd123").val();
                            var nums =top.$("#nums123").val();
                            if (nums==""){
                                layer.msg('请输入数量', {
                                    btnAlign: 'c',
                                    time: 3000, //20s后自动关闭
                                    btn: ['确定']
                                });
                            }else {
                                $.ajax({
                                    //几个参数需要注意一下
                                    type: "POST",//方法类型
                                    dataType: "json",//预期服务器返回的数据类型
                                    url: "/overGoods/addOverGoodsInStock" ,//url
                                    data: {productNum:productNum,testRemarks:testRemarks,num:nums},
                                    success: function (result) {
                                        console.log(result);//打印服务端返回的数据(调试用)
                                        if (result.success >0) {

                                            layer.msg('操作成功', {
                                                btnAlign: 'c',
                                                time: 3000, //20s后自动关闭
                                                btn: ['确定']
                                            });
                                            table.reload('idTestOverIn');
                                        }else{
                                            layer.msg('操作失败', {
                                                btnAlign: 'c',
                                                time: 3000, //20s后自动关闭
                                                btn: ['确定']
                                            });
                                        }
                                    },
                                    error : function() {
                                        alert("异常！");
                                    }
                                });
                                layer.close(index);
                            }
                        },
                        btn2:function (index) {
                            layer.close(index);
                        }
                    })
                    break;
                case 'deletes':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else {
                        layer.confirm('确定删除',{btn: ['确定', '取消'], title: "提示"},function(index){
                            $.ajax({
                                //几个参数需要注意一下
                                type: "POST",//方法类型
                                dataType: "json",//预期服务器返回的数据类型
                                url: "/overGoods/deleteOverGoodsInStock" ,//url
                                data: {deList:JSON.stringify(deList)},
                                success: function (result) {
                                    if (result.success>0) {
                                        layer.msg('操作成功', {
                                            btnAlign: 'c',
                                            time: 3000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                        table.reload('idTestOverIn')
                                    }else{
                                        layer.msg('操作失败', {
                                            btnAlign: 'c',
                                            time: 3000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                    }
                                },
                                error : function() {
                                    alert("异常！");
                                }
                            });
                            layer.close(index);
                        });
                    }
                    break;
            }
        });
        var $ = layui.$, active = {
            reload:function () {
                var startDate = $("#startDateSearchOverGoodsInstock").val();
                var productNum = $("#productNumSearchOverGoodsInstock").val();
                var goodsName = $("#goodsNameSearchOverGoodsInstock").val();
                var specifications = $("#goodsSpecificationsSearchOverGoodsInstock").val();
                var operator = $("#operatorSearchOverGoodsInstock").val();
                var endDate = $("#endDateSearchOverGoodsInstock").val();
                table.reload('idTestOverIn',{
                    url:'/overGoods/searchOverGoodsInStock',
                    where:{productNum:productNum,goodsName:goodsName,specifications:specifications,operator:operator,startDate:startDate,endDate:endDate}  ,
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                })

            }
        };

        $('.demoTableOverGoodsInstock .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        laydate.render({
            elem: '#startDateSearchOverGoodsInstock' //指定元素
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#endDateSearchOverGoodsInstock' //指定元素
            ,type: 'datetime'
        });
    });
    layui.use(['upload'],function(){
        var $ = layui.jquery,
            upload = layui.upload;
//指定允许上传的文件类型
        upload.render({
            elem: '#upload'
            ,url: '/overGoods/uploadInStock'
            ,accept: 'file' //普通文件
            ,exts: 'xlsx' //只允许上传excel文件
            ,done: function(res){
                if(res.code == 0){ //上传成功
                    layer.msg(res.msg);
                    table.reload('idTest')
                }else{
                    layer.msg('上传失败');
                }
            }
            ,error: function(index, upload){
                layer.msg('上传失败');
            }
        });
    });
    function searchExist() {
       var productNumAdd = $("#productNumAdd123").val();
       console.log(productNumAdd+"***********************");
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "/order/searchProductOrder1" ,//url
            data: {productNumAdd:productNumAdd},
            success: function (result) {
                if (result.success>0) {
                    $("#productNumAddSS").hide();
                }else{
                   $("#productNumAddSS").show();
                    $("#productNumAdd123").val("");
                }
            }
        });
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "/overGoods/searchOverGoodsInStock2" ,//url
            data: {productNum:productNumAdd},
            success: function (result) {
                console.log("*************"+result.count)
                if (result.count>0) {
                    $("#productNumAddS").show();
                    $("#productNumAdd123").val("");
                }else{
                    $("#productNumAddS").hide();
                }
            }
        });
    }
    var unSelected = "#999";
    var selected = "#333";
    $(function () {
        $("select").css("color", unSelected);
        $("option").css("color", selected);
        $("select").change(function () {
            var selItem = $(this).val();
            if (selItem == $(this).find('option:first').val()) {
                $(this).css("color", unSelected);
            } else {
                $(this).css("color", selected);
            }
        });
    })
</script>

</body>
</html>